/**
 * @desc 赛事执行-选手称重
 * @author yd_zhaorongjun
 */
<template>
  <div>
    <template>
      <el-tabs v-model="activeName" type="card" @tab-click="handleClick">
        <el-tab-pane label="个人项目" name="weighingInd">
          <div class="demo-input-suffix gl_searchBox">
            <el-row :gutter="20">
              <!-- 按状态 -->
              <el-col :md="6" :lg="4">
                <p>{{ $t('search.state') }}</p>
                <el-select v-model="isValid" size="mini" :placeholder="$t('search.placeholder_State')" filterable clearable @change="changeApproved">
                  <el-option value="" label="全部" />
                  <el-option v-for="item in approveStatusList" :key="item.code" :value="item.code" :label="item.name" />
                </el-select>
              </el-col>
              <!-- 按机构 -->
              <el-col :md="6" :lg="4">
                <p>按机构</p>
                <el-select v-model="Api_GET_EventsManagementWeighingQO.DelegationId" size="mini" placeholder="按机构" filterable clearable @change="refreshList()">
                  <el-option value="" label="全部" />
                  <el-option v-for="item in delegationList" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>
              </el-col>
              <!-- 项目级别 -->
              <el-col :md="6" :lg="4">
                <p>按项目级别</p>
                <el-cascader ref="cascader" v-model="cascaderDataList" :options="cascaderEventList" clearable :props="{ value: 'id', label: 'name',checkStrictly: true }" placeholder="请选择项目级别" size="mini" style="width: 100%;" @change="changeCascader" />
              </el-col>
              <!-- 人员 -->
              <el-col :md="6" :lg="4">
                <p>人员</p>
                <el-input v-model="Api_GET_EventsManagementWeighingQO.Filter" placeholder="人员" size="mini" clearable @change="refreshList()" />
              </el-col>
              <el-col :md="6" :lg="4">
                <!-- 查询按钮 -->
                <el-button style="margin-top:27px" type="primary" size="mini" @click="refreshList()">{{ $t('button.query') }}</el-button>
                <!-- 重置按钮 -->
                <el-button style="margin-top:27px" type="warning" size="mini" @click="refreshSearchForm">{{ $t('button.Reset') }}</el-button>
              </el-col>
            </el-row>
          </div>
          <div v-loading="drawLoading" :element-loading-text="drawLoadingText">
            <el-row :gutter="20" class="gl_my_15">
              <!-- 添加选手 -->
              <el-col :span="10">
                <!-- <el-button-group style="vertical-align: bottom;margin-left: 10px;"> -->
                <el-button type="primary" size="mini" @click="clickBatchPass()">批量通过</el-button>
                <el-button type="primary" plain size="mini" @click="clickBatchNoPass()">批量不通过</el-button>
                <el-button type="primary" size="mini" @click="clickAllPass()">一键全部通过</el-button>
                <el-button type="primary" plain size="mini" @click="clickAllNoPass()">一键全部不通过</el-button>
                <!-- </el-button-group> -->
              </el-col>
              <el-col :span="14" style="text-align:right">
                <div class="pdf_btn gl_ml_30"  @click="comexcel('WeighinListByNOC')">
                  <img class="PDFimg" src="@/assets/images/EXE.svg" alt="">
                  <span>按机构生成excel称重表</span>
                  <!-- <el-button :loading="downloadloading" type="primary" size="mini">按机构生成excel称重表</el-button> -->
                </div>
                <div class="pdf_btn gl_ml_30" @click="comRecord('WeighinListByNOC')">
                  <img class="PDFimg" src="@/assets/images/PDF.svg" alt="">
                  <span>按机构生成称重表</span>
                </div>
                <div class="pdf_btn gl_ml_30" @click="comRecord('WeighinListByEvent')">
                  <img class="PDFimg" src="@/assets/images/PDF.svg" alt="">
                  <span>按级别生成称重表</span>
                </div>
              </el-col>
            </el-row>
            <el-table v-loading="loading" :data="tableData" stripe size="mini" style="width: 100%;" @selection-change="selection">
              <el-table-column type="selection" label-class-name="selection" />
              <!-- 序号 -->
              <el-table-column type="index" label="序号" align="center" width="55" />
              <!-- 运动员头像 -->
              <el-table-column label="头像" align="center" width="90">
                <template slot-scope="{row}">
                  <img class="athletePhoto" :src="getStaticFileUrl(row.sourceRegister && row.sourceRegister.imagePath)" alt="" @error="errorPhoto">
                </template>
              </el-table-column>
              <!-- 姓名 -->
              <el-table-column prop="sourceRegister.name" label="姓名" width="100" />
              <!-- 证件号 -->
              <el-table-column prop="sourceRegister.idCardNumber" label="证件号" width="150" align="center" />
              <!-- 所属机构 -->
              <el-table-column prop="delegation.name" label="所属机构" width="120">
                <template slot-scope="{ row }">
                  <el-tooltip class="item" effect="dark" :content="row.delegation && row.delegation.name ? row.delegation.name : ''" placement="top">
                    <div class="gl_7_ellipsis">{{ row.delegation && row.delegation.name ? row.delegation.name : '' }}</div>
                  </el-tooltip>
                </template>
              </el-table-column>
              <!-- <el-table-column prop="delegation.name" label="所属机构" width="180" /> -->
              <!-- 性别 -->
              <!-- <el-table-column label="性别" width="60" align="center">
                <template slot-scope="{row}">
                  <div v-for="item in dict.gender" :key="item.code">
                    {{ item.code === (row.sourceRegister && row.sourceRegister.sourceRegister && row.sourceRegister.sourceRegister.genderCode) ? item.value: '' }}
                  </div>
                </template>
              </el-table-column> -->
              <!-- 项目名称 -->
              <!-- <el-table-column prop="event.longName" label="项目名称" min-width="170" /> -->
              <el-table-column label="项目名称" min-width="170">
                <template slot-scope="{row}">
                  <div v-for="item in row.entrys" :key="item.id" class="event_Name">{{ item.event.eventGroup.category.name + " " || '' }} {{ item.event.eventGroup.name + " " || '' }} {{ item.event.name + " " || '' }} {{ item.teamNo ? item.teamNo+ "组" : '' }}</div>
                </template>
              </el-table-column>
              <!-- 一次称重(KG) -->
              <el-table-column prop="weight1" label="一次称重(KG)" width="110" align="center">
                <template slot-scope="{row}">
                  <div v-for="item in row.entrys" :key="item.id" class="weighingsIsValid">{{ !item.weight1 && item.weight1 !== 0 ? '--' : item.weight1 }}</div>
                </template>
              </el-table-column>
              <!-- 二次称重 -->
              <el-table-column prop="weight2" label="二次称重(KG)" width="110" align="center">
                <template slot-scope="{row}">
                  <div v-for="item in row.entrys" :key="item.id" class="weighingsIsValid">{{ !item.weight2 && item.weight2 !== 0 ? '--' : item.weight2 }}</div>
                </template>
              </el-table-column>
              <!-- 称重状态 -->
              <el-table-column label="称重状态" align="center" width="100">
                <template slot-scope="{row}">
                  <div v-for="item in row.entrys" :key="item.id" class="weighingsIsValid">
                    <span v-if="item.isWeighingValid" class="gl_color_success">
                      <i class="el-icon-success" />
                      <span>已通过</span>
                    </span>
                    <span v-if="item.isWeighingValid === false" class="gl_color_error">
                      <i class="el-icon-error" />
                      <span>不通过</span>
                    </span>
                    <span v-if="item.isWeighingValid == null" class="gl_color_gay">
                      <i class="el-icon-error" />
                      <span>未审查</span>
                    </span>
                  </div>
                </template>
              </el-table-column>
              <!-- 出生日期 -->
              <!-- <el-table-column label="出生日期" width="100" align="center">
                <template slot-scope="{row}">
                  <span v-if="row.sourceRegister && row.sourceRegister.birthDate">
                    {{ row.sourceRegister.birthDate | FormatDate('yyyy-MM-dd') }}
                  </span>
                </template>
              </el-table-column> -->
              <!-- 操作 -->
              <el-table-column fixed="right" :label="$t('table.actions')" width="200">
                <template slot-scope="{row}">
                  <!-- 编辑按钮 -->
                  <!-- <div class="actions_div gl_mr_15">
                    <el-button size="mini" type="text" @click="editWeighingEvent(row, item)">
                      {{ $t('table.edit') }}
                    </el-button>
                  </div> -->
                  <div class="actions_div">
                    <div v-for="item in row.entrys" :key="item.id">
                      <!-- 编辑按钮 -->
                      <el-button size="mini" type="text" @click="editWeighingEvent(row, item)">
                        {{ $t('table.edit') }}
                      </el-button>
                      <!-- 添加称重按钮 -->
                      <el-button size="mini" type="text" @click="editWeighing(item)">
                        添加称重
                      </el-button>
                      <!-- 通过按钮 -->
                      <el-button v-if="item.isWeighingValid == null || item.isWeighingValid === false" size="mini" type="text" @click="editVerify(item, true)">
                        <span class="gl_color_warning">通过</span>
                      </el-button>
                      <!-- 不通过按钮 -->
                      <el-button v-if="item.isWeighingValid == null || item.isWeighingValid" size="mini" type="text" @click="editVerify(item, false)">
                        <span class="gl_color_warning">不通过</span>
                      </el-button>
                    </div>
                  </div>
                </template>
              </el-table-column>
            </el-table>
            <el-row class="gl_pt_20" style="text-align: center;">
              <el-pagination
                :current-page="Api_GET_EventsManagementWeighingQO.Page"
                :page-size="Api_GET_EventsManagementWeighingQO.MaxResultCount"
                :total="totalPage"
                layout="total,sizes,prev,pager,next,jumper"
                :page-sizes="[10, 20, 30, 40]"
                @size-change="sizeChange"
                @current-change="pageIndexChange"
              />
            </el-row>
          </div>
        </el-tab-pane>
        <el-tab-pane label="团体项目" name="weighingTeam">
          <div class="demo-input-suffix gl_searchBox">
            <el-row :gutter="20">
              <!-- 按状态 -->
              <el-col :md="6" :lg="4">
                <p>{{ $t('search.state') }}</p>
                <el-select v-model="isValid" size="mini" :placeholder="$t('search.placeholder_State')" filterable clearable @change="changeApproved">
                  <el-option value="" label="全部" />
                  <el-option v-for="item in approveStatusList" :key="item.code" :value="item.code" :label="item.name" />
                </el-select>
              </el-col>
              <!-- 按机构 -->
              <el-col :md="6" :lg="4">
                <p>按机构</p>
                <el-select v-model="Api_GET_EventsManagementWeighingQO.DelegationId" size="mini" placeholder="按机构" filterable clearable @change="refreshList()">
                  <el-option value="" label="全部" />
                  <el-option v-for="item in delegationList" :key="item.id" :label="item.name" :value="item.id" />
                </el-select>
              </el-col>
              <!-- 项目级别 -->
              <el-col :md="6" :lg="4">
                <p>按项目级别</p>
                <el-cascader ref="cascader" v-model="cascaderDataList" :options="cascaderEventList" clearable :props="{ value: 'id', label: 'name',checkStrictly: true }" placeholder="请选择项目级别" size="mini" style="width: 100%;" @change="changeCascader" />
              </el-col>
              <!-- 人员 -->
              <el-col :md="6" :lg="4">
                <p>人员</p>
                <el-input v-model="Api_GET_EventsManagementWeighingQO.Filter" placeholder="人员" size="mini" clearable @change="refreshList()" />
              </el-col>
              <el-col :md="6" :lg="4">
                <!-- 查询按钮 -->
                <el-button style="margin-top:27px" type="primary" size="mini" @click="refreshList()">{{ $t('button.query') }}</el-button>
                <!-- 重置按钮 -->
                <el-button style="margin-top:27px" type="warning" size="mini" @click="refreshSearchForm">{{ $t('button.Reset') }}</el-button>
              </el-col>
            </el-row>
          </div>
          <div v-loading="drawLoading" :element-loading-text="drawLoadingText">
            <el-row :gutter="20" class="gl_my_15">
              <!-- 添加选手 -->
              <el-col :span="10">
                <!-- <el-button-group style="vertical-align: bottom;margin-left: 10px;"> -->
                <el-button type="primary" size="mini" @click="clickBatchPass()">批量通过</el-button>
                <el-button type="primary" plain size="mini" @click="clickBatchNoPass()">批量不通过</el-button>
                <el-button type="primary" size="mini" @click="clickAllPass()">一键全部通过</el-button>
                <el-button type="primary" plain size="mini" @click="clickAllNoPass()">一键全部不通过</el-button>
                <!-- </el-button-group> -->
              </el-col>
              <el-col :span="14" style="text-align:right">
                <div class="pdf_btn gl_ml_30"  @click="comexcel('WeighinListByNOC')">
                  <img class="PDFimg" src="@/assets/images/EXE.svg" alt="">
                  <span>按机构生成excel称重表</span>
                  <!-- <el-button :loading="downloadloading" type="primary" size="mini">按机构生成excel称重表</el-button> -->
                </div>
                <div class="pdf_btn gl_ml_30" @click="comRecord('WeighinListByNOC')">
                  <img class="PDFimg" src="@/assets/images/PDF.svg" alt="">
                  <span>按机构生成称重表</span>
                </div>
                <div class="pdf_btn gl_ml_30" @click="comRecord('WeighinListByEvent')">
                  <img class="PDFimg" src="@/assets/images/PDF.svg" alt="">
                  <span>按级别生成称重表</span>
                </div>
              </el-col>
            </el-row>
            <el-table v-loading="loading" :data="tableData" stripe size="mini" default-expand-all style="width: 100%;" @selection-change="selection">
              <el-table-column type="expand">
                <template slot-scope="props">
                  <el-table :data="props.row.entrys[0].memberEntrys" stripe size="mini" :summary-method="getSummaries" show-summary style="width: 100%;">
                    <!-- 运动员头像 -->
                    <el-table-column label="头像" align="center" width="100">
                      <template slot-scope="{row}">
                        <img class="athletePhoto" :src="getStaticFileUrl(row.competitionRegister.sourceRegister && row.competitionRegister.sourceRegister.imagePath)" alt="" @error="errorPhoto">
                      </template>
                    </el-table-column>
                    <!-- 姓名 -->
                    <el-table-column label="姓名" width="200">
                      <template slot-scope="{row}">
                        <div>{{ row.competitionRegister.name }}{{ row.weightClass && row.weightClass.name ? ' (' + row.weightClass.name + ') ' : '' }}</div>
                      </template>
                    </el-table-column>
                    <!-- 证件号 -->
                    <el-table-column prop="competitionRegister.sourceRegister.idCardNumber" label="证件号" min-width="180" align="center" />
                    <!-- 一次称重(KG) -->
                    <el-table-column prop="weight1" label="一次称重(KG)" width="120" align="center">
                      <template slot-scope="{row}">
                        <div>{{ !row.weight1 && row.weight1 !== 0 ? '--' : row.weight1 }}</div>
                      </template>
                    </el-table-column>
                    <!-- 二次称重 -->
                    <el-table-column prop="weight2" label="二次称重(KG)" width="120" align="center">
                      <template slot-scope="{row}">
                        <div>{{ !row.weight2 && row.weight2 !== 0 ? '--' : row.weight2 }}</div>
                      </template>
                    </el-table-column>
                    <el-table-column :label="$t('table.actions')" width="260">
                      <template slot-scope="{row}">
                        <el-button size="mini" type="text" @click="editWeighingTeam(row, props.row.entrys[0])">
                          添加称重
                        </el-button>
                      </template>
                    </el-table-column>
                  </el-table>
                </template>
              </el-table-column>
              <el-table-column type="selection" label-class-name="selection" />
              <!-- 序号 -->
              <el-table-column type="index" label="序号" align="center" width="55" />
              <!-- 名称 -->
              <!-- <el-table-column prop="name" label="名称" width="200" /> -->
              <el-table-column label="名称" min-width="200">
                <template slot-scope="{row}">
                  <div v-for="item in row.entrys" :key="item.id" class="event_Name">{{ item.event.eventGroup.category.name + " " || '' }} {{ item.event.eventGroup.name + " " || '' }} {{ item.event.name + " " || '' }} {{ item.teamNo ? item.teamNo+ "组" : '' }}</div>
                </template>
              </el-table-column>
              <!-- 所属机构 -->
              <!-- <el-table-column prop="delegation.name" label="所属机构" width="220" /> -->
              <el-table-column prop="delegation.name" label="所属机构" width="120">
                <template slot-scope="{ row }">
                  <el-tooltip class="item" effect="dark" :content="row.delegation && row.delegation.name ? row.delegation.name : ''" placement="top">
                    <div class="gl_7_ellipsis">{{ row.delegation && row.delegation.name ? row.delegation.name : '' }}</div>
                  </el-tooltip>
                </template>
              </el-table-column>
              <!-- 项目名称 -->
              <!-- <el-table-column prop="event.longName" label="项目名称" min-width="170" /> -->
              <el-table-column label="项目名称" min-width="170">
                <template slot-scope="{row}">
                  <div v-for="item in row.entrys" :key="item.id" class="event_Name">{{ item.event.eventGroup.category.name + " " || '' }} {{ item.event.eventGroup.name + " " || '' }} {{ item.event.name + " " || '' }}</div>
                </template>
              </el-table-column>
              <el-table-column label="称重状态" align="center" width="100">
                <template slot-scope="{row}">
                  <div v-for="item in row.entrys" :key="item.id" class="weighingsIsValid">
                    <span v-if="item.isWeighingValid" class="gl_color_success">
                      <i class="el-icon-success" />
                      <span>已通过</span>
                    </span>
                    <span v-if="item.isWeighingValid === false" class="gl_color_error">
                      <i class="el-icon-error" />
                      <span>不通过</span>
                    </span>
                    <span v-if="item.isWeighingValid == null" class="gl_color_gay">
                      <i class="el-icon-error" />
                      <span>未审查</span>
                    </span>
                  </div>
                </template>
              </el-table-column>
              <el-table-column :label="$t('table.actions')" width="200">
                <template slot-scope="{row}">
                  <div class="actions_div">
                    <div v-for="item in row.entrys" :key="item.id">
                      <!-- 通过按钮 -->
                      <el-button v-if="item.isWeighingValid == null || item.isWeighingValid === false" size="mini" type="text" @click="editVerify(item, true)">
                        <span class="gl_color_warning">通过</span>
                      </el-button>
                      <!-- 不通过按钮 -->
                      <el-button v-if="item.isWeighingValid == null || item.isWeighingValid" size="mini" type="text" @click="editVerify(item, false)">
                        <span class="gl_color_warning">不通过</span>
                      </el-button>
                    </div>
                  </div>
                </template>
              </el-table-column>
            </el-table>
            <el-row class="gl_pt_20" style="text-align: center;">
              <el-pagination
                :current-page="Api_GET_EventsManagementWeighingQO.Page"
                :page-size="Api_GET_EventsManagementWeighingQO.MaxResultCount"
                :total="totalPage"
                layout="total,sizes,prev,pager,next,jumper"
                :page-sizes="[10, 20, 30, 40]"
                @size-change="sizeChange"
                @current-change="pageIndexChange"
              />
            </el-row>
          </div>
        </el-tab-pane>
      </el-tabs>
    </template>
    <!-- 添加称重弹框 -->
    <el-dialog title="添加称重" class="gl_dialog_TitleLine" :visible.sync="dialogVisible_weight" :close-on-click-modal="false" width="440px">
      <el-scrollbar v-loading="dialogLoading" wrap-class="scrollbar-wrapper gl_dialog_height">
        <el-row class="transferBox" type="flex" justify="center">
          <el-form ref="SiSTKWEventsManagementUpdateWeightInput" class="gl_form_mini" :model="SiSTKWEventsManagementUpdateWeightInput" :rules="playerDTO_Rules" label-position="right" label-width="120px" style="padding-right: 20px;">
            <el-row :gutter="40">
              <el-col class="newWeight_title">
                {{ editWeighing_event }}
              </el-col>
              <el-col :span="24">
                <!-- 一次称重 -->
                <el-form-item label="一次称重" label-width="120px" prop="weight1">
                  <el-input-number v-model="SiSTKWEventsManagementUpdateWeightInput.weight1" size="small" controls-position="right" :min="0" style="width:75%;margin-right: 5px" /> kg
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <!-- 二次称重 -->
                <el-form-item label="二次称重" label-width="120px" prop="weight2">
                  <el-input-number v-model="SiSTKWEventsManagementUpdateWeightInput.weight2" size="small" controls-position="right" :min="0" style="width:75%;margin-right: 5px" /> kg
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-row>
      </el-scrollbar>
      <span slot="footer" class="dialog-footer">
        <!-- 取消按钮 -->
        <el-button size="mini" @click="dialogVisible_weight = false">{{ $t('button.cancel') }}</el-button>
        <!-- 保存按钮 -->
        <el-button type="primary" :loading="submitLoading" size="mini" @click="saveWeight()">{{ $t('button.save') }}</el-button>
      </span>
    </el-dialog>

    <!-- 修改公斤级弹框 -->
    <el-dialog title="修改公斤级" class="gl_dialog_TitleLine" :visible.sync="dialogVisible_edit" :close-on-click-modal="false" width="480px">
      <el-scrollbar v-loading="dialogLoading" wrap-class="scrollbar-wrapper gl_dialog_height">
        <el-form ref="playerDTO_edit" class="gl_form_mini" :model="playerDTO_edit" label-position="right" label-width="130px" style="padding-right: 20px;">
          <el-row :gutter="20" class="gl_mt_20">
            <el-col :span="24">
              <!-- 选择报项 -->
              <el-form-item label="选择报项" label-width="110px">
                <el-select v-model="Api_PUT_EventsManagementEntryForAdminQO.newEventId" style="width:85%" size="mini">
                  <el-option v-for="item in eidtEventList" :key="item.id" :label="item.eventLongName" :value="item.id" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </el-scrollbar>
      <span slot="footer" class="dialog-footer">
        <!-- 取消按钮 -->
        <el-button size="mini" @click="dialogVisible_edit = false">{{ $t('button.cancel') }}</el-button>
        <!-- 保存按钮 -->
        <!-- <el-button type="primary" :loading="submitLoading" size="mini" @click="editEntry()">{{ $t('button.save') }}</el-button> -->
        <el-button v-if="Api_PUT_EventsManagementEntryForAdminQO.newEventId != '-1'" type="primary" :loading="submitLoading" size="mini" @click="editEntry()">{{ $t('button.save') }}</el-button>
        <!-- 保存按钮, 选择不参与 （-1） 的时候调删除api  -->
        <el-button v-else type="primary" :loading="submitLoading" size="mini" @click="deleteEntry()">{{ $t('button.save') }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { getToken } from '@/lib/auth';
import { api_GET_DownLoadFileAddHeader } from '@/extend/api/file';
import { errorText } from '@/lib';
import { mapState, mapActions } from 'vuex';
import defaultGameLogo from '@/assets/images/face_default.png';
import { translateByCode } from '@/lib/getTransData';
// import { CopyData } from '@/lib';
import { api_GET_EventsManagementCategory, api_GET_EventsManagementEntryDelegationListByCompetitionCompetitionId, api_GET_EventsManagementWeighing, api_PUT_EventsManagementWeighingWeighingInfo, api_PUT_EventsManagementWeighingWeighingStatus, api_POST_EventsManagementEntryQueryEventsToEntryForRegisters, api_DELETE_EventsManagementEntryForAdmin, api_PUT_EventsManagementEntryForAdmin } from '@/extend/api/gameswaggerApi/app';
import { SiSTKWEventsManagementUpdateWeightInput, SiSTKWEventsManagementGetEntryEventsInput, Api_GET_EventsManagementWeighingQO, Api_PUT_EventsManagementEntryForAdminQO } from '@/lib/form/game/swaggerForm';
import { EidtEventListData } from '@/lib/form/game/qualificationForm';
import validator from '@/lib/validate/index.js';
export default {
  name: 'PlayersWeighing',
  data() {
    return {
      tokenInfo: getToken(),
      downloadloading: false,
      defaultGameLogo: defaultGameLogo,
      SiSTKWEventsManagementUpdateWeightInput: new SiSTKWEventsManagementUpdateWeightInput(),
      SiSTKWEventsManagementGetEntryEventsInput: new SiSTKWEventsManagementGetEntryEventsInput(),
      Api_GET_EventsManagementWeighingQO: new Api_GET_EventsManagementWeighingQO(),
      // * 表单: 3-1-管理员：更改队伍或人员的报项，更改队伍成员【注意同类别团体赛应该不允许参加多个队伍】
      Api_PUT_EventsManagementEntryForAdminQO: new Api_PUT_EventsManagementEntryForAdminQO(),
      eidtEventListData: new EidtEventListData(),
      cascaderEventList: [], // 级联筛选框的下拉数据
      cascaderDataList: [''], // 用于存放级联筛选框选中的数据
      eventId: '',
      delegationList: [], // 机构列表的下拉数据
      isValid: '', // 计算状态用
      approveStatusList: [ // 状态下拉列表
        {
          code: 'null',
          name: '未审查'
        },
        {
          code: true,
          name: '已通过'
        },
        {
          code: false,
          name: '不通过'
        }
      ],
      gameId: '', // 赛事id
      loading: false,
      dialogLoading: false,
      submitLoading: false,
      drawLoading: false,
      drawLoadingText: '',
      currentPage: 1,
      totalPage: 0,
      SelectionList: [], // 选中的数据
      dialogVisible_weight: false,
      dialogVisible_edit: false,
      eidtEventList: [],
      tableData: [],
      editWeighing_event: '', // 修改称重弹框里的项目名称
      playerDTO_edit: {},
      playerDTO_Rules: {
        // 第一次称重
        weight1: [
          {
            validator(rule, value, callback) {
              callback(validator.checkNumberPointForFourt(value, '请输入数字且不超过4位小数'));
            },
            trigger: 'blur'
          }
        ],
        // 第二次称重
        weight2: [
          {
            validator(rule, value, callback) {
              callback(validator.checkNumberPointForFourt(value, '请输入数字且不超过4位小数'));
            },
            trigger: 'blur'
          }
        ]
      },
      activeName: 'weighingInd',
      oldEventList: []
    };
  },
  computed: {
    ...mapState({
      cache: state => state.dict.cache,
      dict: state => state.dict.dict,
      dictAll: state => state.dict.dictAll
    })
  },
  watch: {
    activeName: {
      handler(val) {
        this.cascaderEventList = [];
        this.tableData = [];
        this.Api_GET_EventsManagementWeighingQO.MaxResultCount = 10;
        if (val === 'weighingInd') {
          for (let i = 0; i < this.oldEventList.length; i++) {
            const item = this.oldEventList[i];
            if (item.registerTypeCode === 'I' && item.eventTypeCode === 'Competitive') { // 只选个人的项目
              this.cascaderEventList.push(item);
            }
          }
        } else {
          for (let i = 0; i < this.oldEventList.length; i++) {
            const item = this.oldEventList[i];
            if (item.registerTypeCode !== 'I' && item.eventTypeCode === 'Competitive') { // 只选个人的项目
              this.cascaderEventList.push(item);
            }
          }
        }
        this.refreshSearchForm();
        this.cascaderEventList.unshift({ id: '', name: '全部' });
        console.log('activeName', this.cascaderEventList);
      }
    }
  },
  created() {
    this.gameId = this.$route.params.id;
    this.getDictByType(['district']);
    this.getDict();
    this.api_GET_EventsManagementCategory();
    this.getDelegationList();
    this.Api_GET_EventsManagementWeighingQO.IsValid = '';
    this.isValid = '';
    this.Api_GET_EventsManagementWeighingQO.IsAllForValidStatus = true;
    this.activeName = 'weighingInd';
    this.Api_GET_EventsManagementWeighingQO.IsIndividual = true; // 个人是true
    this.refreshList();
  },
  methods: {
    ...mapActions({ getDictByType: 'dict/getDictByType', getDict: 'dict/getDict' }),
    // 称重表格合计的自定义计算
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      // eslint-disable-next-line no-unused-vars
      let weight1 = [0, 0];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计';
          return;
        }
        if (index === 3 || index === 4) {
          const values = data.map(item => item[column.property] === null || item[column.property] === '' ? null : Number(item[column.property]));
          if (index === 3) {
            weight1 = values;
          }
          if (index === 4) {
            if (!values.every(value => value === null)) {
              for (let i = 0; i < values.length; i++) {
                // eslint-disable-next-line eqeqeq
                values[i] = values[i] == null ? weight1[i] : values[i];
              }
            }
          }
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return ((prev * 100 + curr * 100) / 100).toFixed(2);
              } else {
                return prev;
              }
            }, 0);
            // sums[index] += ' 元';
          } else {
            sums[index] = '--';
          }
        }
      });

      return sums;
    },
    // 获取项目类别列表
    api_GET_EventsManagementCategory() {
      const _this = this;
      const data = {
        CompetitionId: _this.gameId,
        IncludeEventGroup: true,
        IncludeEvent: true
      };
      api_GET_EventsManagementCategory(data).then(res => {
        for (let i = 0; i < res.items.length; i++) {
          // eslint-disable-next-line prefer-const
          let item = res.items[i];
          if (item.eventTypeCode === 'Competitive') { // 只选竞技类型的项目
            item.children = item.eventGroups;
            for (let j = 0; j < item.children.length; j++) {
            // eslint-disable-next-line prefer-const
              let jtem = item.children[j];
              for (let k = 0; k < jtem.events.length; k++) {
                // eslint-disable-next-line prefer-const
                let ktem = jtem.events[k];
                ktem.name = ktem.longName || ktem.name;
              }
              jtem.children = jtem.events;
            }
          }
        }
        _this.oldEventList = res.items;
        _this.cascaderEventList = []; // 深拷贝常用方法
        for (let j = 0; j < res.items.length; j++) {
          const jtem = res.items[j];
          if (jtem.registerTypeCode === 'I' && jtem.eventTypeCode === 'Competitive') { // 只选个人的项目
            _this.cascaderEventList.push(jtem);
          }
        }
        _this.cascaderEventList.unshift({ id: '', name: '全部' });
        console.log('oldEventList', _this.oldEventList);
        console.log('cascaderEventList', _this.cascaderEventList);
      }, () => {
        _this.$message({ type: 'error', message: '获取项目类别列表失败' });
      });
    },
    // 查询机构列表
    getDelegationList() {
      api_GET_EventsManagementEntryDelegationListByCompetitionCompetitionId(this.gameId).then(res => {
        this.delegationList = res;
      }, () => {
        this.$message({ type: 'error', message: '获取机构列表失败' });
      });
    },
    // 刷新列表
    refreshList(page) {
      this.loading = true;
      this.Api_GET_EventsManagementWeighingQO.CompetitionId = this.gameId;
      this.Api_GET_EventsManagementWeighingQO.Page = page || 1;
      this.Api_GET_EventsManagementWeighingQO.SkipCount = (this.Api_GET_EventsManagementWeighingQO.Page - 1) * this.Api_GET_EventsManagementWeighingQO.MaxResultCount;
      api_GET_EventsManagementWeighing(this.Api_GET_EventsManagementWeighingQO).then(res => {
        console.log(res);
        this.tableData = res.items;
        this.totalPage = res.totalCount;
        this.loading = false;
      }, () => {
        this.$message({ type: 'error', message: '获取称重列表失败' });
      });
    },
    // 重置搜索表单
    refreshSearchForm() {
      this.Api_GET_EventsManagementWeighingQO = new Api_GET_EventsManagementWeighingQO();
      this.Api_GET_EventsManagementWeighingQO.IsValid = '';
      this.isValid = '';
      this.Api_GET_EventsManagementWeighingQO.IsAllForValidStatus = true;
      this.Api_GET_EventsManagementWeighingQO.IsIndividual = this.activeName === 'weighingInd';
      this.cascaderDataList = [''];
      this.refreshList();
    },
    // 审核状态下拉改变
    changeApproved(val) {
      // 全部 ： IsAllForValidStatus == true && Api_GET_EventsManagementWeighingQO.IsValid ==''
      // 未审查 ： IsAllForValidStatus == false && Api_GET_EventsManagementWeighingQO.IsValid ==''
      // 已通过 ： IsAllForValidStatus == false && Api_GET_EventsManagementWeighingQO.IsValid == true
      // 不通过 ： IsAllForValidStatus == false && Api_GET_EventsManagementWeighingQO.IsValid == false

      if (val === '') {
        this.Api_GET_EventsManagementWeighingQO.IsAllForValidStatus = true;
      } else {
        this.Api_GET_EventsManagementWeighingQO.IsAllForValidStatus = false;
      }
      this.Api_GET_EventsManagementWeighingQO.IsValid = val;
      if (val === 'null') {
        this.Api_GET_EventsManagementWeighingQO.IsValid = '';
      }
      this.refreshList();
    },
    // 获取静态文件
    getStaticFileUrl(relativeUrl) {
      if (!relativeUrl) return '';
      return WEB_CONFIG.VUE_APP_STATIC_FILE_RUL + relativeUrl;
    },
    errorPhoto() {
      const img = event.srcElement;
      img.src = this.defaultGameLogo;
    },
    // 地址栏改变
    changeCascader() {
      this.Api_GET_EventsManagementWeighingQO.CategoryId = this.cascaderDataList[0] || '';
      this.Api_GET_EventsManagementWeighingQO.EventGroupId = this.cascaderDataList[1] || '';
      this.Api_GET_EventsManagementWeighingQO.EventId = this.cascaderDataList[2] || '';
      this.eventId = this.cascaderDataList[2] || '';
      this.refreshList();
    },
    // 选中的数据
    selection(val) {
      this.SelectionList = [];
      val.forEach(item => {
        const _arrayData = item.entrys.map(jtem => jtem.id);
        this.SelectionList = this.SelectionList.concat(_arrayData);
      });
    },
    // 批量不通过按钮
    clickBatchNoPass() {
      if (this.SelectionList.length > 0) {
        const _confirmStr = '是否批量不通过已勾选的运动员？';
        this.$confirm(_confirmStr, translateByCode('alert.warning'), {
          confirmButtonText: translateByCode('alert.confirm'),
          cancelButtonText: translateByCode('alert.cancel'),
          type: 'warning'
        }).then(() => {
          api_PUT_EventsManagementWeighingWeighingStatus({ entryIds: this.SelectionList, isWeighingValid: false, competitionId: this.gameId }).then(res => {
            this.$message({
              // 操作成功
              message: '操作成功',
              type: 'success'
            });
            this.refreshList(this.Api_GET_EventsManagementWeighingQO.Page);
          }, (error) => {
            this.$message({ type: 'error', message: error.error.message });
          });
        });
      } else {
        this.$message({
          // 请选择运动员
          message: '请选择运动员',
          type: 'warning'
        });
      }
    },
    // 一键不通过按钮
    clickAllNoPass() {
      const _this = this;
      const _confirmStr = '是否一键全部不通过所有的运动员？';
      this.$confirm(_confirmStr, translateByCode('alert.warning'), {
        confirmButtonText: translateByCode('alert.confirm'),
        cancelButtonText: translateByCode('alert.cancel'),
        type: 'warning'
      }).then(() => {
        _this.drawLoading = true;
        _this.drawLoadingText = '一键全部不通过中';
        api_PUT_EventsManagementWeighingWeighingStatus({ entryIds: null, isWeighingValid: false, competitionId: this.gameId }).then(res => {
          this.$message({
            // 操作成功
            message: '操作成功',
            type: 'success'
          });
          _this.drawLoading = false;
          this.refreshList(this.Api_GET_EventsManagementWeighingQO.Page);
        }, (error) => {
          this.$message({ type: 'error', message: error.error.message });
          _this.drawLoading = false;
        });
      });
    },
    // 批量通过按钮
    clickBatchPass() {
      if (this.SelectionList.length > 0) {
        const _confirmStr = '是否要批量通过已勾选的运动员？';
        this.$confirm(_confirmStr, translateByCode('alert.warning'), {
          confirmButtonText: translateByCode('alert.confirm'),
          cancelButtonText: translateByCode('alert.cancel'),
          type: 'warning'
        }).then(() => {
          api_PUT_EventsManagementWeighingWeighingStatus({ entryIds: this.SelectionList, isWeighingValid: true, competitionId: this.gameId }).then(res => {
            this.$message({
              // 操作成功
              message: '操作成功',
              type: 'success'
            });
            this.refreshList(this.Api_GET_EventsManagementWeighingQO.Page);
          }, (error) => {
            this.$message({ type: 'error', message: error.error.message });
          });
        });
      } else {
        this.$message({
          // 请选择运动员
          message: '请选择运动员',
          type: 'warning'
        });
      }
    },
    // 一键通过按钮
    clickAllPass() {
      const _this = this;
      const _confirmStr = '是否要一键全部通过所有运动员？';
      this.$confirm(_confirmStr, translateByCode('alert.warning'), {
        confirmButtonText: translateByCode('alert.confirm'),
        cancelButtonText: translateByCode('alert.cancel'),
        type: 'warning'
      }).then(() => {
        _this.drawLoading = true;
        _this.drawLoadingText = '一键全部通过中';
        api_PUT_EventsManagementWeighingWeighingStatus({ entryIds: null, isWeighingValid: true, competitionId: this.gameId }).then(res => {
          this.$message({
            // 操作成功
            message: '操作成功',
            type: 'success'
          });
          _this.drawLoading = false;
          this.refreshList(this.Api_GET_EventsManagementWeighingQO.Page);
        }, (error) => {
          this.$message({ type: 'error', message: error.error.message });
          _this.drawLoading = false;
        });
      });
    },
    // 审核
    editVerify(row, isValid) {
      const _this = this;
      api_PUT_EventsManagementWeighingWeighingStatus({ entryIds: [row.id], isWeighingValid: isValid, competitionId: _this.gameId }).then(res => {
        this.$message({
          // 操作成功
          message: '操作成功',
          type: 'success'
        });
        _this.refreshList(this.Api_GET_EventsManagementWeighingQO.Page);
      });
    },
    // 修改称重级别
    editWeighingEvent(row, item) {
      const _this = this;
      _this.dialogVisible_edit = true;
      _this.dialogLoading = true;
      _this.SiSTKWEventsManagementGetEntryEventsInput = new SiSTKWEventsManagementGetEntryEventsInput();
      _this.SiSTKWEventsManagementGetEntryEventsInput.competitionId = _this.gameId;
      _this.SiSTKWEventsManagementGetEntryEventsInput.registerId = row.sourceRegister.id;
      _this.SiSTKWEventsManagementGetEntryEventsInput.delegationId = null;
      _this.Api_PUT_EventsManagementEntryForAdminQO = new Api_PUT_EventsManagementEntryForAdminQO();
      // 报项是团体的时候传团体EntryId
      _this.Api_PUT_EventsManagementEntryForAdminQO.oldEntryId = item.id;
      api_POST_EventsManagementEntryQueryEventsToEntryForRegisters(_this.SiSTKWEventsManagementGetEntryEventsInput).then(res => {
        _this.eidtEventList = res;
        const empty = {
          id: '-1',
          eventLongName: '不参加'
        };
        _this.eidtEventList.unshift(empty);
        _this.dialogLoading = false;
        console.log('eidtEventList', _this.eidtEventList);
      }, () => {
        _this.$message({ type: 'error', message: '获取已存在人员可报的赛事项目列表失败' });
        _this.dialogLoading = false;
      });
    },
    // 修改报项
    editEntry() {
      const _this = this;
      _this.submitLoading = true;
      if (_this.Api_PUT_EventsManagementEntryForAdminQO.newEventId === '') {
        this.$message({
          // 请选择报项
          message: '请选择报项',
          type: 'warning'
        });
        _this.submitLoading = false;
      } else {
        api_PUT_EventsManagementEntryForAdmin(this.Api_PUT_EventsManagementEntryForAdminQO).then(res => {
          this.$message({
            // 修改成功！
            message: translateByCode('alert.editSuccessfully'),
            type: 'success'
          });
          _this.dialogVisible_edit = false;
          _this.submitLoading = false;
          _this.refreshList(this.Api_GET_EventsManagementWeighingQO.Page);
        })
          .catch(
            error => {
              const _msg = error.error.message || error.message;
              this.$message({
                duration: 15000,
                showClose: true,
                message: _msg,
                type: 'error'
              });
            }
          );
      }
    },
    // 修改报项保存按钮, 选择不参与 （-1） 的时候调删除api
    deleteEntry() {
      const _this = this;
      _this.submitLoading = true;
      var _ids = [];
      _ids.push(_this.Api_PUT_EventsManagementEntryForAdminQO.oldEntryId);
      api_DELETE_EventsManagementEntryForAdmin({ ids: _ids }).then(res => {
        this.$message({
          // 修改成功！
          message: translateByCode('alert.editSuccessfully'),
          type: 'success'
        });
        _this.dialogVisible_edit = false;
        _this.submitLoading = false;
        _this.refreshList();
      }, () => {
        this.$message({ type: 'error', message: '修改报项失败' });
        _this.submitLoading = false;
      });
    },
    // 修改称重按钮
    editWeighing(row) {
      this.editWeighing_event = row.event.longName;
      this.SiSTKWEventsManagementUpdateWeightInput.entryId = row.id;
      this.SiSTKWEventsManagementUpdateWeightInput.weight1 = Number(row.weight1);
      this.SiSTKWEventsManagementUpdateWeightInput.weight2 = Number(row.weight2);
      this.dialogVisible_weight = true;
    },
    // 团体修改称重按钮
    editWeighingTeam(row, teamRow) {
      this.editWeighing_event = row.competitionRegister.name;
      this.SiSTKWEventsManagementUpdateWeightInput.entryId = row.id;
      this.SiSTKWEventsManagementUpdateWeightInput.weight1 = Number(row.weight1);
      this.SiSTKWEventsManagementUpdateWeightInput.weight2 = Number(row.weight2);
      this.dialogVisible_weight = true;
    },
    // 修改称重
    saveWeight() {
      const _this = this;
      _this.submitLoading = true;
      this.SiSTKWEventsManagementUpdateWeightInput.weight1 = Number(this.SiSTKWEventsManagementUpdateWeightInput.weight1);
      this.SiSTKWEventsManagementUpdateWeightInput.weight2 = Number(this.SiSTKWEventsManagementUpdateWeightInput.weight2);
      api_PUT_EventsManagementWeighingWeighingInfo(this.SiSTKWEventsManagementUpdateWeightInput).then(res => {
        this.$message({
          // 修改成功！
          message: translateByCode('alert.editSuccessfully'),
          type: 'success'
        });
        _this.submitLoading = false;
        _this.dialogVisible_weight = false;
        _this.refreshList(this.Api_GET_EventsManagementWeighingQO.Page);
      }, () => {
        this.$message({ type: 'error', message: '修改失败' });
        _this.submitLoading = false;
      });
    },
    comexcel(ContestResults) {
      var _this = this;
      const reportVO = {};
      reportVO.reportName = ContestResults;
      _this.downloadloading = true;
      // reportVO.format = '';
      reportVO.CompetitionId = this.gameId;
      let fileName = '称重表(按机构)' + '.xlsx';
      const tempUrl = `/api/excel`;
      api_GET_DownLoadFileAddHeader(tempUrl, fileName, reportVO).then(res => {
        _this.downloadloading = false;
      }).catch(error => {
        _this.downloadloading = false;
        errorText(error).then(function(text) {
          _this.$message({ type: 'error', message: text });
        });
      });
    },
    // 生成比赛记录单
    comRecord(ContestResults) {
      var _this = this;
      const reportVO = {};
      reportVO.reportName = ContestResults;
      reportVO.format = 'PDF';
      reportVO.CompetitionId = this.gameId;
      let fileName = '';
      if (ContestResults === 'WeighinListByEvent') {
        fileName = '称重表(按级别)' + '.pdf';
        reportVO.EventId = this.eventId;
      } else {
        fileName = '称重表(按机构)' + '.pdf';
      }
      const tempUrl = `/api/app/events-management/report`;
      api_GET_DownLoadFileAddHeader(tempUrl, fileName, reportVO).then(res => {
        _this.downloadLoading = false;
      }).catch(error => {
        _this.downloadLoading = false;
        errorText(error).then(function(text) {
          _this.$message({ type: 'error', message: text });
        });
      });
    },
    handleClick(val) {
      // this.tableData = [];
      // this.Api_GET_EventsManagementWeighingQO.MaxResultCount = 10;
      // this.refreshList();
    },
    sizeChange(MaxResultCount) {
      this.Api_GET_EventsManagementWeighingQO.MaxResultCount = MaxResultCount;
      this.refreshList();
    },
    pageIndexChange(currentPage) {
      this.refreshList(currentPage);
    }
  }
};
</script>
<style lang="scss" scoped>
  .PDFimg{
    height: 28px;
    width: 25px;
    vertical-align: middle;
  }
  .pdf_btn{
    cursor: pointer;
    display: inline-block;
  }
  .pdf_btn>span{
    padding-left: 5px;
    display: inline-block;
    vertical-align: middle;
  }
  .pdf_btn:hover span{
    color: #1890ff;
  }
  .newWeight_title{
    font-size: 16px;
    color: #606266;
    text-align: left;
    margin-bottom: 25px;
    margin-top: 20px;
    font-weight: bold;
    text-align: center;
  }
  .athletePhoto{
    width: 60px;
    height: 70px;
    vertical-align: middle;
  }
  .weighingsIsValid{
    // display: list-item;
    // list-style: none;
    min-height: 23px;
  }
  .actions_div{
    display: inline-block;
    vertical-align: middle;
  }
  .event_Name{
    padding: 2px 0;
  }
</style>
